
"""
    面包屑导航
    category: 类别对象：一级，二级，三级
    一级：返回一级；二级：返回一级+二级；三级：返回一级+二级+三级
"""
def get_breadcrumb(category):

    breadcrumb = {
        'cat1': '','cat2': '','cat3': ''
    }

    # 说明category是一级
    if category.parent == None:
        breadcrumb['cat1'] = category

    # 说明category是三级
    elif category.subs.count() == 0:
        cat2 = category.parent
        breadcrumb['cat1'] = cat2.parent
        breadcrumb['cat2'] = cat2
        breadcrumb['cat3'] = category

    # 说明category是二级
    else:
        breadcrumb['cat1'] = category.parent
        breadcrumb['cat2'] = category
    return breadcrumb
